<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>编辑用户</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<%@include file="../common/common_ui.jsp" %>
  </head>
  
  <body>
  
  <form id="frm" name="frm" class="definewidth m20" action="" method="post">
	
		<div id="check_alert" class="alert alert-danger mb_0 ng-binding" style="display: none;text-align:left">
			<span id="check_content"></span>
			<span class="glyphicon glyphicon-remove"></span>
		</div>
		<div id="msg_alert" class="alert alert-success alert-dismissible"
			role="alert" style="display: none;text-align:left">
			<span id="msg_content"></span>
			<span class="glyphicon glyphicon-remove"></span>
		</div>
		
		<table class="table table-bordered table-hover definewidth m10">
		
		    <tr>
				<td>账号：</td>
				<td><input name="userName" id="userName" class="form-control"
						value="${userInfo.userName}" style="width: 250px; height: 40px"></input></td>
			</tr>
			<tr>
				<td>姓名：</td>
				<td><input name="realName" id="realName" class="form-control" value="${userInfo.realName}"
						style="width: 250px; height: 40px"></input></td>
			</tr>
		
  	     </table>
  	     
  	     <center>
            <button type="button" id="btnSave" class="btn btn-primary">保存</button>&nbsp;&nbsp;
          	<button type="button" class="btn btn-default" onclick="window.close()">关闭</button>        
         </center> 	           
             
   </form>

	  <input type="hidden" value="${userInfo.id}" name="id" id="id">
	  <input type="hidden" value="${method}" name="method" id="method">
	  <script type="text/javascript">
	  function check() {
			if ($('#userName').val() == null || $('#userName').val().trim() == "") {
				$("#check_alert").show();
				$("#check_content").text("用户名不为空！");
				$("#userName").focus();
				return false;
			};
			if ($('#realName').val() == null || $('#realName').val().trim() == "") {
				$("#check_alert").show();
				$("#check_content").text("姓名不为空！");
				$("#realName").focus();
				return false;
			};
			if ($('#realName').val().trim().length > 50) {
				$("#check_alert").show();
				$("#check_content").text("姓名最长50字！");
				$("#realName").focus();
				return false;
			};
			if ($('#userName').val().trim().length > 20) {
				$("#check_alert").show();
				$("#check_content").text("账号最长20字！");
				$("#userName").focus();
				return false;
			};
			return true;
		};
	
	  
	  $(function (){
	  		$("#btnSave").click(function (){
	  			var id = $("#id").val();
	  			var userName = $("#userName").val();
	  			var realName = $("#realName").val();
	  			var password = $("#password").val();
	  			var method = $("#method").val();
	  			if(check()){
	  				$.post("<%=path %>/userInfo/editUser.do",{
	  					times:new Date().getTime(),
						id:id,
						userName:userName,
						realName:realName,
						password:password,
						method:method
	  				},function(data){
	  					var message = data.message;
	  					if (message == "success") {
	  						$("#msg_alert").show();
	  						$("#msg_content").text("成功！");
	  					} else {
	  						$("#msg_alert").show();
	  						$("#msg_content").text(message);
	  					}
	  				});
	  			}
	  		});
	  	});
	  			
	$(function(){
	/*
	* 关闭提示
	*/
	$(".glyphicon-remove").click(function(){
		$("#check_alert").hide();
		$("#msg_alert").hide();
	});
	});
	</script>
  </body>
</html>
